#include "OLBanner.h"
#include "OLAppTemplateDefs.h"

#include <QtGui/QPainter>
#include <QtGui/QLinearGradient>
#include <QtGui/QFontMetrics>

OLBanner::OLBanner(QWidget *parent) :
        QWidget(parent), m_opacity(1.0)
{
    resize(parent->size());
}

void OLBanner::paintEvent(QPaintEvent* e)
{
    QPainter p(this);

    p.setOpacity(m_opacity);
    p.setPen(OLStyles::buttonHighlightBorder());
//    p.setBrush(Qt::NoBrush);
    p.setBrush(OLStyles::buttonHighlightBrush(rect()));
    p.drawRect(rect());
//    p.drawLine(0, 0, width(), 0);
//    p.drawLine(0, height()-1, width(), height()-1);

//    p.setPen(Qt::white);
//    p.drawText(rect().adjusted(19,-1,-21,-1), Qt::AlignCenter | Qt::TextWordWrap, m_text);
    p.setPen(OLStyles::textHighlightColor());
    p.drawText(rect().adjusted(20,0,-20,0), Qt::AlignCenter | Qt::TextWordWrap, m_text);
}

void OLBanner::setOpacity(qreal opacity)
{
    m_opacity = opacity;
    update();
}

qreal OLBanner::opacity()
{
    return m_opacity;
}

void OLBanner::setText(const QString& text)
{
    m_text = text;
    adjustSize(parentWidget()->size());
}

void OLBanner::adjustSize(const QSize& parentsize)
{
    QFontMetrics metrics(font());
    QRect textRect = metrics.boundingRect(parentWidget()->rect().adjusted(20,0,-20,0), Qt::AlignCenter | Qt::TextWordWrap, m_text);
    resize(parentsize.width(), textRect.height()+20);
}

